@extends('layouts._admin')

@section('title')
    商品列表
@endsection

@section('content')
    <div class="app-content">
        <div ui-butterbar></div>
        <a href class="off-screen-toggle hide" data-toggle="class:off-screen" data-target=".app-aside"></a>
        <div class="app-content-body fade-in-up">
            <!-- COPY the content from "tpl/" -->
            <div class="hbox hbox-auto-xs hbox-auto-sm">
                <div class="col">
                    <div class="wrapper-md ng-scope">
                        <div class="panel panel-default">
                            <div class="panel-heading">
                                商品列表
                            </div>
                            <div class="table-responsive">
                                <div id="DataTables_Table_0_wrapper" class="dataTables_wrapper form-inline dt-bootstrap no-footer">
                                    <div class="panel-body">
                                        @if ($message = Session::get('success'))
                                            <div class="alert alert-success">
                                                <p>{{ $message }}</p>
                                            </div>
                                        @endif

                                        @if ($message = Session::get('error'))
                                            <div class="alert alert-danger">
                                                <p>{{ $message }}</p>
                                            </div>
                                        @endif


                                        <a style="float: left;margin-right: 10px;" href="">
                                            <button type="button" class="btn btn-sm btn-primary">
                                                <i class="glyphicon glyphicon-plus"></i>
                                                Excel导入商品
                                            </button>
                                        </a>


                                        {{--<a href="{{route('goods.update.upload')}}">--}}
                                        {{--<button type="button" class="btn btn-sm btn-info">--}}
                                        {{--更新当天上传商品索引--}}
                                        {{--</button>--}}
                                        {{--</a>--}}

                                    </div>
                                    <div class="row">

                                        <div class="col-sm-12">
                                            <table ui-jq="dataTable" ui-options="{sAjaxSource: 'api/datatable.json',aoColumns: [{ mData: 'engine' },{ mData: 'browser' },{ mData: 'platform' },{ mData: 'version' },{ mData: 'grade' }]}" class="table table-striped b-t b-b dataTable no-footer" id="DataTables_Table_0" role="grid" aria-describedby="DataTables_Table_0_info">
                                                <thead>
                                                <tr role="row">
                                                    <th style="width: 100px;" class="sorting" tabindex="0"
                                                        aria-controls="DataTables_Table_0" rowspan="1" colspan="1">序号</th>
                                                    <th style="width: 100px;" class="sorting" tabindex="0" aria-controls="DataTables_Table_0" rowspan="1" colspan="1">分类名字</th>
                                                    <th style="width: 100px;" class="sorting" tabindex="0" aria-controls="DataTables_Table_0" rowspan="1" colspan="1">排序</th>
                                                    <th style="width: 100px;" class="sorting" tabindex="0" aria-controls="DataTables_Table_0" rowspan="1" colspan="1">是否使用</th>

                                                </thead>
                                                <tbody>
                                                @foreach($category as $key => $cate)
                                                    <tr role="row" class="odd">
                                                        <td>{{$cate->cate_id}}</td>
                                                        <td>{{$cate->cate_name}}</td>
                                                        <td class="sortc">
                                                            <input type="text" name="sort" value="{{$cate->cate_sort}}" cate="{{$cate->cate_id}}">
                                                        </td>
                                                        <td>
                                                            @if($cate->is_use)
                                                                <a class="btn btn-danger is_use" href="javascript:;" cate="{{$cate->cate_id}}" use="0">关闭</a>
                                                            @else
                                                                <a class="btn btn-info is_use" href="javascript:;" cate="{{$cate->cate_id}}" use="1">开启</a>
                                                            @endif
                                                        </td>
                                                    </tr>
                                                @endforeach
                                                </tbody>
                                            </table>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

@endsection

@section('js')
    <script>
        $(function(){

            $('.is_use').click(function(){
                var id = $(this).attr('cate');
                var use = $(this).attr('use');
                var self = $(this);
                $.ajax({
                    url: "category/use",
                    type: 'post',
                    dataType: 'json',
                    headers: { 'X-CSRF-TOKEN' : '{{ csrf_token() }}' },
                    data: {id:id,use:use},
                    success:function(data){
                        if(!data){
                            alert('error');
                        }
                    }
                });
            });

            $('.sortc input').blur(function(){
                var id = $(this).attr('cate');
                var val = parseInt($(this).val());
                var self = $(this);
                $.ajax({
                    url: "category/sort",
                    type: 'post',
                    dataType: 'json',
                    headers: { 'X-CSRF-TOKEN' : '{{ csrf_token() }}' },
                    data: {id:id,val:val},
                    success:function(data){
                        if(data){
                            self.val(val);
                        }else {
                            alert('error');
                        }
                    }
                });

            })

        })
    </script>
@endsection

